package DSRStructure;

import java.util.ArrayList;
import java.util.Date;

import Message.PayLoadMessage;

public class SendBuffer {
	ArrayList<SendBufferEntry> buffer = new ArrayList<SendBufferEntry>();
	private final static long discardTime = 10;
	
	public SendBuffer(){
	
	}
	
	
	
	public ArrayList<SendBufferEntry> getBuffer() {
		return buffer;
	}



	public void addMessage(PayLoadMessage message){
		buffer.add(new SendBufferEntry(message));
	}
	
	public void cleanBuffer(){
		ArrayList<SendBufferEntry> tempBuffer = (ArrayList<SendBufferEntry>)buffer.clone();
		for (SendBufferEntry entry : tempBuffer) {
			Date currDate = new Date();
			long diffDate = (currDate.getTime() - entry.getTimestamp().getTime())/1000;
			if(diffDate > discardTime){
				buffer.remove(entry);
			}
		}
	}



	public void delete(ArrayList<SendBufferEntry> entryToDelete) {
		for (SendBufferEntry entry : entryToDelete) {
			buffer.remove(entry);
		}
		
	}
	
	
}
